package mwt.xml.xdbforms.schemalayer.types;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import mwt.xml.xdbforms.dblayer.metadata.TableMetaData;
import mwt.xml.xdbforms.dblayer.metadata.impl.ColumnMetaData;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;

/**
 *
 *
 * @deprecated Ogni bool viene mappato come un bit
 *
 * @author Gianfranco Murador
 */
public class XmlBool extends XmlTypes {

    /**
     * @deprecated
     */
    public XmlBool() {
    }

    /**
     * @deprecated
     * @param doc
     */
    public XmlBool(Document doc) {
        super(doc);
    }

    /**
     * @deprecated
     * @param typeName
     */
    public XmlBool(String typeName) {
        super(typeName);
    }

    /**
     * @deprecated 
     * @param column
     * @param tableMetaData
     */
    private void buildFragment(int column, TableMetaData tableMetaData) {

        Element xtype, restriction, maxLength;
        Integer maxlenght;

        xtype = doc.createElementNS("xs", "simpleType");
        xtype.setAttribute("name", typeName);

        fragment = doc.createDocumentFragment();
        restriction = doc.createElementNS("xs", "restriction");
        restriction.setAttribute("base", "xs:boolean");
        maxLength = doc.createElementNS("xs", "maxLength");
        try {
            maxlenght = tableMetaData.getColumnDisplaySize(column);
            maxLength.setAttribute("value", maxlenght.toString());
        } catch (SQLException ex) {
            Logger.getLogger(XmlBool.class.getName()).log(Level.SEVERE, null, ex);
        }


        // create fragment

        xtype.appendChild(restriction);
        restriction.appendChild(maxLength);
        fragment.appendChild(xtype);

    }

    /**
     * @deprecated 
     * @param cmd
     * @return
     */
    @Override
    public DocumentFragment getSchemaType(ColumnMetaData cmd) {



        return null;


    }

    @Override
    public Object getXSchemaToJavaType(String baseType, String value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

